home *** CD-ROM | disk | FTP | other *** search
/ Gamers Delight 2 / Gamers Delight 2.iso / Aminet / game / demo / GDS_SND.lha / sound / snd.c < prev   
C/C++ Source or Header  |  1993-12-31  |  4KB  |  150 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <dos.h>
  5. #include <signal.h>
  6. #include <proto/exec.h>
  7.  
  8. #include <GameSmith:include/libraries/libraries.h>
  9. #include <GameSmith:include/libraries/libptrs.h>
  10. #include <GameSmith:include/sound/sound.h>
  11. #include <GameSmith:include/proto/all.h>
  12.  
  13. void ctrl_c(int);
  14.  
  15. struct sound_struct sample1,sample2;    /* 2 structs in case of stereo sample */
  16. int stop=0;                                /* ctrl-C break flag */
  17.  
  18. /***************************************************************************/
  19.  
  20. main(argc,argv)
  21. int argc;
  22. char *argv[];
  23.  
  24. {
  25.     int err,echo,temp,old_prio;
  26.  
  27.     if (argc < 2)
  28.         {
  29.         printf("\nUsage: SND file_name [loop value] [echo divisor] [volume cnt]\n");
  30.         printf("           [volume decrement] [period cnt] [period decrement] [period]\n");
  31.         exit(01);
  32.         }
  33.     signal(SIGINT,&ctrl_c);            /* set up break handler ANSI style */
  34.     sample1.flags=SND_FAST;            /* load sample to Fast RAM if available */
  35.     sample2.flags=SND_FAST;
  36.     if (gs_open_libs(DOS|GRAPHICS,0)) /* need DOS for reading file, and Graphics */
  37.         exit(02);                        /* sound sys uses Graphics lib to determine */
  38.                                             /* whether a PAL or NTSC machine for timing */
  39.     if (err=gs_load_iff_sound(&sample1,&sample2,argv[1]))
  40.         {
  41.         if (err == -4)                    /* If not IFF, try to load raw */
  42.             {
  43.             if (err=gs_load_raw_sound(&sample1,argv[1]))
  44.                 {
  45.                 printf("\nError loading raw sample.  Code = %d\n",err);
  46.                 gs_close_libs();
  47.                 exit(03);
  48.                 }
  49.             else
  50.                 printf("\nRaw Sample\n\n");
  51.             }
  52.         else if (err == -7)            /* if couldn't load 2nd channel */
  53.             {
  54.             printf("\nUnable to load 2nd sound channel for stereo play\n");
  55.             }
  56.         else
  57.             {
  58.             printf("\nError loading IFF sample.  Code = %d\n",err);
  59.             gs_close_libs();
  60.             exit(03);
  61.             }
  62.         }
  63.     else
  64.         {
  65.         if (sample2.data)
  66.             printf("\nIFF 8SVX Stereo Sample ({<*>})\n\n");
  67.         else
  68.             printf("\nIFF 8SVX Mono Sample\n\n");
  69.         }
  70.     if (argc >= 3)                        /* check for repeat value */
  71.         {
  72.         sample1.repeat=atoi(argv[2]);
  73.         sample2.repeat=atoi(argv[2]);
  74.         }
  75.     if (argc >= 4)                        /* check for echo divisor */
  76.         {
  77.         echo=atoi(argv[3]);
  78.         if (echo > 1)
  79.             {
  80.             temp=sample1.length/echo;
  81.             if (temp)
  82.                 {
  83.                 sample1.loop=sample1.data+((sample1.length-temp)*2);
  84.                 sample2.loop=sample2.data+((sample2.length-temp)*2);
  85.                 }
  86.             }
  87.         }
  88.     if (argc >= 5)                        /* check for volume count */
  89.         {
  90.         sample1.volcnt=atoi(argv[4]);
  91.         sample2.volcnt=atoi(argv[4]);
  92.         }
  93.     if (argc >= 6)                        /* check for volume decrement */
  94.         {
  95.         sample1.volfade=atoi(argv[5]);
  96.         sample2.volfade=atoi(argv[5]);
  97.         }
  98.     if (argc >= 7)                        /* check for period count */
  99.         {
  100.         sample1.percnt=atoi(argv[6]);
  101.         sample2.percnt=atoi(argv[6]);
  102.         }
  103.     if (argc >= 8)                        /* check for period decrement */
  104.         {
  105.         sample1.perfade=atoi(argv[7]);
  106.         sample2.perfade=atoi(argv[7]);
  107.         }
  108.     if (argc >= 9)                        /* check for new period value */
  109.         {
  110.         sample1.period=atoi(argv[8]);
  111.         sample2.period=atoi(argv[8]);
  112.         }
  113.     if (gs_open_sound(1,0,0,(4096/2)))    /* open sound system & alloc channels */
  114.         {
  115.         gs_free_sound(&sample1);
  116.         if (sample2.data)
  117.             gs_free_sound(&sample2);
  118.         printf("\nError opening sound system\n");
  119.         gs_close_libs();
  120.         exit(04);
  121.         }
  122.     Disable();                    /* in case need to sync 2 channels */
  123.     gs_start_sound(&sample1,CHANNEL0);
  124.     if (sample2.data)            /* check if need to start 2nd channel @ same time */
  125.         gs_start_sound(&sample2,CHANNEL1);
  126.     else
  127.         gs_start_sound(&sample1,CHANNEL1);
  128.     Enable();                    /* reenable interrupts */
  129.     old_prio=gs_task_prio(-128);                /* lowest priority while sample plays */
  130.     while ((gs_sound_check()) && (!stop))    /* wait for all channels idle */
  131.         chkabort();                                    /* and check for abort signal */
  132.     gs_task_prio(old_prio);
  133.     gs_stop_sound(CHANNEL0);                    /* stop all sounds (if still active) */
  134.     gs_stop_sound(CHANNEL1);
  135.     gs_close_sound();                                /* shut down sound system */
  136.     gs_free_sound(&sample1);                    /* release sound data when done */
  137.     if (sample2.data)
  138.         gs_free_sound(&sample2);
  139.     gs_close_libs();                                /* close libs and end */
  140. }
  141.  
  142. /***************************************************************************/
  143.  
  144. void ctrl_c(signal)            /* ctrl-C handling ANSI fashion (SAS/C 6.xx) */
  145. int signal;
  146.  
  147. {
  148.     stop=1;                        /* set flag to quit */
  149. }
  150.